package org.linlinjava.litemall.admin.web;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.linlinjava.litemall.admin.annotation.RequiresPermissionsDesc;
import org.linlinjava.litemall.admin.vo.StatVo;
import org.linlinjava.litemall.core.util.ResponseUtil;
import org.linlinjava.litemall.db.service.LitemallStatService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/admin/stat")
@Validated
public class AdminStatController {

    @Resource
    private LitemallStatService statService;

    @RequiresPermissions("admin:stat:user")
    @RequiresPermissionsDesc(menu = {"统计管理","用户统计"},button = "查询")
    @GetMapping("/user")
    public Object statUser(){
        List<Map> rows = statService.statUser();
        String[] columns = new String[]{"day","users"};
        StatVo vo = new StatVo();
        vo.setRows(rows);
        vo.setColumns(columns);
        return ResponseUtil.ok(vo);
    }

    @RequiresPermissions("admin:stat:order")
    @RequiresPermissionsDesc(menu = {"统计管理","订单统计"},button = "查询")
    @GetMapping("/order")
    public Object statOrder(){
        List<Map> rows = statService.statOrder();
        String[] columns = new String[]{"day", "orders", "customers", "amount", "pcr"};
        StatVo vo = new StatVo();
        vo.setRows(rows);
        vo.setColumns(columns);
        return ResponseUtil.ok(vo);
    }

    @RequiresPermissions("admin:stat:goods")
    @RequiresPermissionsDesc(menu = {"统计管理","商品统计"},button = "查询")
    @GetMapping("/goods")
    public Object statGoods(){
        List<Map> rows = statService.statGoods();
        String[] columns = new String[]{"day", "orders", "products", "amount"};
        StatVo vo = new StatVo();
        vo.setRows(rows);
        vo.setColumns(columns);
        return ResponseUtil.ok(vo);
    }

}
